package com.hello.Launcher;

import com.hello.MainMenuScreen;
import com.hello.R;
import com.hello.games.GameFactoryBuilder;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class LaunchAppFromGame extends Activity{
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);	
        setContentView(R.layout.appautolauncherdialog);
        
        final Button yesButton = (Button) findViewById(R.id.okButtonLuncher);
        yesButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
            	Intent intent = new Intent(LaunchAppFromGame.this,MainMenuScreen.class);	
            	startActivity(intent);
            	finish();
            }
        });
        
        final Button noButton = (Button) findViewById(R.id.cancelButtonLuncher);
        noButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
            	Class game = GameFactoryBuilder.getInstance().getRandomGame();
        		Intent myIntent = new Intent(LaunchAppFromGame.this,game);
        		startActivityForResult(myIntent,2);
            }
        });
	}
        
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		switch (requestCode) {
		case 2:
			if (resultCode == RESULT_CANCELED){
            	Intent intent = new Intent(this,MainMenuScreen.class);
            	startActivity(intent);	
			}
			else{
				try{
				}
				catch (Exception e) {
					
				}
			}
			finish();
			break;
		default:
			super.onActivityResult(requestCode, resultCode, data);
			break;
		}
		
	}
	
	

}
